// JavaScript Document
var reg = {
	emailHintMessage:"请输入你用来登录的用户名，这将是你登录wzx网的帐号...",
	errorEmailMessage:"对不起，可使用的字符只能为英文与 '_ - ',长度在5-20个字符，注意不要使用空格。",
	duplicateEmailMessage:"对不起，这个邮箱已经被使用了，请重新输入",
	emptyEmailMessage:"你还没有填写你的邮箱地址",
	validEmailMessage:"这个邮箱可以使用",
	passwordHintMessage:"可以使用英文字母、符号或数字，长度控制在6-20位",
	errorPasswordMessage:"注意密码长度要在6－20个字符以内，而且不要有空格",
	emptyPasswordMessage:"你还没有设置登录密码",
	password2HintMessage:"为了确保密码的准确性，请再次输入你的密码",
	errorPassword2Message:"对不起，你两次输入的密码不一致，请重新输入",
	emptyPassword2Message:"你需要再次输入你的密码",
	nicknameHintMessage:"给自己起一个漂亮的名号，中文、英文都可以",
	emptyNicknameMessage:"你还没有为自己起名字呢",
	errorNicknameMessage:"对不起，昵称只能使用10个字符以内的中英文字符或数字，请重新输入",
	sensitiveNicknameMessage:"对不起，昵称中含有不允许的文字：{0}",
	vcodeHintMessage:"出于安全考虑，请你输入下面显示的内容",
	emptyVcodeMessage:"你还没有输入验证码",
	errorVcodeMessage:"对不起，你输入的验证码有错误，请重新输入",
	emptyLocationMessage:"你还没有选择你居住的地区",
	registerRuleMessage:"对不起，你必须同意我们的服务条款",
	processMessage:"信息提交中，请稍候",
	failureMessage:"注册失败，请检查后再试，谢谢",
	regTag:false,
	usernameStatus:false,
	pwdStatus:false,
	pwd2Status:false,
	nicknameStatus:false,
	vcodeStatus:false,
	setHintVisibility:function(id,css,str){	
		var o = $(id);	
		if (o)	{
			o.className = css;	
			o.innerHTML = str;	
		}
	},
	checkUserName:function(){
		$("emailText_hint").className =  "ml12 zoom c_a5";
		$("emailText_hint").innerHTML = this.emailHintMessage;
	},
	checkPwd:function(){
		$("passwordText_hint").className =  "ml12 zoom c_a5";
		$("passwordText_hint").innerHTML = this.passwordHintMessage;
	},
	checkPwd_confirm:function(){
		$("password2Text_hint").className =  "ml12 zoom c_a5";
		$("password2Text_hint").innerHTML = this.password2HintMessage;
	},
	checkNickname:function(){
		$("nicknameText_hint").className =  "ml12 zoom c_a5";
		$("nicknameText_hint").innerHTML = this.nicknameHintMessage;
	},
	checkvcode:function(){
		$("vcodeText_hint").className =  "ml12 zoom c_a5";
		$("vcodeText_hint").innerHTML = this.vcodeHintMessage;
	},
	
	checkUserName_resutl:function(){
		if( !this.usernameStatus )	{
			var username = $("emailText").value;
			if(username == ""){
				$("emailText_hint").className =  "ml12 zoom c_red";
				$("emailText_hint").innerHTML = this.emptyEmailMessage;
				this.usernameStatus = false;
				return false;
			}
			if ( !Validator.validateUserName( username ) ){	
				$("emailText_hint").className =  "ml12 zoom c_red";
				$("emailText_hint").innerHTML = this.errorEmailMessage;
				this.usernameStatus = false;
				return false;
			}
			$("emailText_hint").innerHTML = "";
			this.usernameStatus = true;
		}		
		return this.usernameStatus;
	},
	checkPwd_resutl:function(){
		if( !this.pwdStatus )	{
			var pwd = $("passwordText").value;
			if(pwd == ""){
				$("passwordText_hint").className =  "ml12 zoom c_red";
				$("passwordText_hint").innerHTML = this.emptyPasswordMessage;
				this.pwdStatus = false;
				return false;
			}
			if ( !Validator.validatePassword( pwd ) ){
				$("passwordText_hint").className =  "ml12 zoom c_red";
				$("passwordText_hint").innerHTML = this.errorPasswordMessage;
				this.pwdStatus = false;
				return false;
			}
			$("passwordText_hint").innerHTML = "";
			this.pwdStatus = true;	
		}
		return this.pwdStatus;	
	},
	checkPwd_confirm_resutl:function(){
		if( !this.pwd2Status )	{
			var pwd2 = $("password2Text").value;
			if(pwd2 == ""){
				$("password2Text_hint").className =  "ml12 zoom c_red";
				$("password2Text_hint").innerHTML = this.emptyPassword2Message;
				this.pwd2Status = false;
				return false;
			}
			if(pwd2 != $("passwordText").value){
				$("password2Text_hint").className =  "ml12 zoom c_red";
				$("password2Text_hint").innerHTML = this.errorPassword2Message;
				this.pwd2Status = false;
				return false;
			}
			$("password2Text_hint").innerHTML = "";
			this.pwd2Status = true;	
		}
		return this.pwd2Status;
	},
	checkNickname_resutl:function(){
		var nickname = $("nicknameText").value;
		if(!this.nicknameStatus){
			if(nickname == ""){
				$("nicknameText_hint").className =  "ml12 zoom c_red";
				$("nicknameText_hint").innerHTML = this.emptyNicknameMessage;
				this.nicknameStatus = false;
				return false;
			}
			if ( !Validator.validateNickName( nickname ) ){	
				$("nicknameText_hint").className =  "ml12 zoom c_red";
				$("nicknameText_hint").innerHTML = this.errorEmailMessage;
				this.nicknameStatus = false;
				return false;
			}
			$("nicknameText_hint").innerHTML = "";
			this.nicknameStatus = true;
		}
		return this.nicknameStatus;
	},
	checkvcode_resutl:function(){
		var vcode = $("vcodeText").value;
		if(!this.vcodeStatus){
			if(vcode == ""){
				$("vcodeText_hint").className =  "ml12 zoom c_red";
				$("vcodeText_hint").innerHTML = this.emptyVcodeMessage;
				this.vcodeStatus = false;
				return false;
			}
			$("vcodeText_hint").innerHTML = "";
			this.vcodeStatus = true;
		}
		return this.vcodeStatus;
	},
	signUpSubmit:function(){
		//var checkcode1=$('checkcode1').value;
		//var checkcode2=$('checkcode2').value;
		//var checkcode3=$('checkcode3').value;
		var flag=(this.checkUserName_resutl()&&this.checkPwd_resutl()&&this.checkPwd_confirm_resutl()&&this.checkNickname_resutl()&&this.checkvcode_resutl());
		if(flag==true){
			var usernmae = $("emailText").value;
			var password =$("passwordText").value;
			var nickname = $("nicknameText").value;
			var sex=$('maleRadio').checked;
			var vcode = $("vcodeText").value;
			//var areapro=$('nowprov').value;
			//var areacity=$('nowcity').value;
			
			if(typeof pageName != "undefined" && pageName != "")
				var url="/ajax/sign.php?"+pageName;
			else
				var url="/ajax/sign.php";
			var par = [];
			var pars="act=signup";
			par.push(pars);
			var pars="username="+usernmae;
			par.push(pars);
			var pars="password="+password;
			par.push(pars);
			var pars="nickname="+nickname;
			par.push(pars);
			var pars="sex="+sex;
			par.push(pars);

			pars = par.join("&");
			new Ajax.Request(url,{method:"post",parameters:pars,onComplete:function(e){
				var temp=eval("("+e.responseText+")");
				if(temp.rtn_code == "nosession"){
					alert("Need login");
				}else if(temp.rtn_code == "1"){
					alert("注册失败");
				}else{
					$("reg_li_02").className = "";
					$("reg_li_03").className = "on";
					$("reg_info_pannel").innerHTML = temp;
				}
			}});
		}
		else{
			return;
		}
	},
	save_userhead:function(){
		alert("123");
	},
	save_maidou_1:function(){
		var birth = $("inDate").value;
		var edu = $("eduDegreeSelect").options[$("eduDegreeSelect").selectedIndex].value;
		var career = $("careerSelect").options[$("careerSelect").selectedIndex].value;
		var single = document.getElementsByName("marriageRadio");
		for (var i=0; i<single.length; i++){
        	if (single[i].checked){
            	single = single[i].value;
            	break;
        	}
    	}
		var smoke = document.getElementsByName("smokeRadio");
		for (var i=0; i<smoke.length; i++){
        	if (smoke[i].checked){
            	smoke = smoke[i].value;
            	break;
        	}
    	}
		var drink = document.getElementsByName("drinkRadio");
		for (var i=0; i<drink.length; i++){
        	if (drink[i].checked){
            	drink = drink[i].value;
            	break;
        	}
    	}
		var pet = document.getElementsByName("petRadio");
		for (var i=0; i<pet.length; i++){
        	if (pet[i].checked){
            	pet = pet[i].value;
            	break;
        	}
    	}
		var blood = document.getElementsByName("bloodRadio");
		for (var i=0; i<blood.length; i++){
        	if (blood[i].checked){
            	blood = blood[i].value;
            	break;
        	}
    	}
		var intro = $("introText").value;
		single = (typeof single == 'object') ? "" : single;
		smoke = (typeof smoke == 'object') ? "" : smoke;
		drink = (typeof drink == 'object') ? "" : drink;
		pet = (typeof pet == 'object') ? "" : pet;
		blood = (typeof blood == 'object') ? "" : blood;
		if(typeof pageName != "undefined" && pageName != "")
			var url="/ajax/sign.php?"+pageName;
		else
			var url="/ajax/sign.php";
		var par = [];
		var pars="act=maidou_1";
		par.push(pars);
		var pars="birth="+birth;
		par.push(pars);
		var pars="edu="+edu;
		par.push(pars);
		var pars="career="+career;
		par.push(pars);
		var pars="single="+single;
		par.push(pars);
		var pars="smoke="+smoke;
		par.push(pars);
		var pars="drink="+drink;
		par.push(pars);
		var pars="pet="+pet;
		par.push(pars);
		var pars="blood="+blood;
		par.push(pars);
		var pars="intro="+intro;
		par.push(pars);

		pars = par.join("&");
		new Ajax.Request(url,{method:"post",parameters:pars,onComplete:function(e){
			var temp=eval("("+e.responseText+")");
			if(temp.rtn_code == "nosession"){
				alert("Need login"); 
			}else if(temp.rtn_code == "0"){
				location.href="/modules/sign.php?act=maidou_2";
			}
			else{
				$("reg_li_02").className = "";
				$("reg_li_03").className = "on";
				$("reg_info_pannel").innerHTML = temp;
			}
		}});
	}
	
}